package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserPetValue;
import com.happy.cat.project.system.service.IUserPetValueService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 账号宠爱值Controller
 *
 * @author verne
 * @date 2020-08-13
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userPetValue" )
@Api("账号宠爱值 API")
public class UserPetValueController extends BaseController {

    private final IUserPetValueService iUserPetValueService;

    /**
     * 查询账号宠爱值列表
     */
    @ApiOperation(value = "查询账号宠爱值列表",notes = "查询账号宠爱值列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userPetValue:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPetValue userPetValue)
    {
        startPage();
        LambdaQueryWrapper<UserPetValue> lqw = new LambdaQueryWrapper<UserPetValue>();
        if (userPetValue.getType() != null){
            lqw.eq(UserPetValue::getType ,userPetValue.getType());
        }
        if (StringUtils.isNotBlank(userPetValue.getText())){
            lqw.eq(UserPetValue::getText ,userPetValue.getText());
        }
        if (userPetValue.getScore() != null){
            lqw.eq(UserPetValue::getScore ,userPetValue.getScore());
        }
        if (userPetValue.getCurrentScore() != null){
            lqw.eq(UserPetValue::getCurrentScore ,userPetValue.getCurrentScore());
        }
        if (userPetValue.getChangeTime() != null){
            lqw.eq(UserPetValue::getChangeTime ,userPetValue.getChangeTime());
        }
        if (userPetValue.getAccountId() != null){
            lqw.eq(UserPetValue::getAccountId ,userPetValue.getAccountId());
        }
        if (userPetValue.getGift() != null){
            lqw.eq(UserPetValue::getGift ,userPetValue.getGift());
        }
        List<UserPetValue> list = iUserPetValueService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出账号宠爱值列表
     */
    @ApiOperation(value = "导出账号宠爱值列表",notes = "导出账号宠爱值列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userPetValue:export')" )
    @Log(title = "账号宠爱值" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserPetValue userPetValue) {
        LambdaQueryWrapper<UserPetValue> lqw = new LambdaQueryWrapper<UserPetValue>(userPetValue);
        List<UserPetValue> list = iUserPetValueService.list(lqw);
        ExcelUtil<UserPetValue> util = new ExcelUtil<UserPetValue>(UserPetValue. class);
        return util.exportExcel(list, "userPetValue" );
    }

    /**
     * 获取账号宠爱值详细信息
     */
    @ApiOperation(value = "获取账号宠爱值详细信息",notes = "获取账号宠爱值详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userPetValue:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserPetValueService.getById(id));
    }

    /**
     * 新增账号宠爱值
     */
    @ApiOperation(value = "新增账号宠爱值",notes = "新增账号宠爱值",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userPetValue:add')" )
    @Log(title = "账号宠爱值" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPetValue userPetValue) {
        return toAjax(iUserPetValueService.save(userPetValue) ? 1 : 0);
    }

    /**
     * 修改账号宠爱值
     */
    @ApiOperation(value = "修改账号宠爱值",notes = "修改账号宠爱值",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userPetValue:edit')" )
    @Log(title = "账号宠爱值" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPetValue userPetValue) {
        return toAjax(iUserPetValueService.updateById(userPetValue) ? 1 : 0);
    }

    /**
     * 删除账号宠爱值
     */
    @ApiOperation(value = "删除账号宠爱值",notes = "删除账号宠爱值",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userPetValue:remove')" )
    @Log(title = "账号宠爱值" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserPetValueService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
